import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'normalize.css';
import axios from 'axios'
// 导入element
import '@/plugins/element.js'
// 导入过滤器
import '@/plugins/filter.js'
// 导入全局样式
import '@/assets/css/global.css'
// 引入自定义图标
import '@/assets/font_cloudMusic/iconfont.css'
// 解决跨域
import { VueJsonp } from 'vue-jsonp'
import VueCookies from 'vue-cookies'
import utils from '../src/utils/utils.js'
import api from '../src/utils/api'
import CollapseTransition from 'element-ui/lib/transitions/collapse-transition';
import visibility from 'vue-visibility-change';
// import SocketService from '@/utils/socket_service'

Vue.use(VueCookies)
Vue.use(VueJsonp)
Vue.use(visibility);
Vue.prototype.$utils = utils // 注册全局方法
Vue.prototype.$api = api
Vue.prototype.$http = axios
Vue.component(CollapseTransition.name, CollapseTransition)
Vue.$httpRequestList = [];


// // 对服务端进行websocket的连接
// SocketService.Instance.connect()
//     // 其他的组件  this.$socket
// Vue.prototype.$socket = SocketService.Instance

//机器人地址
axios.defaults.baseURL = 'http://www.liulongbin.top:3006/api/'
    // axios.defaults.baseURL = 'https://autumnfish.cn/'
    // axios.defaults.baseURL = '/api'
    // axios.defaults.baseURL = 'http://8.129.133.120:3000/'
    // axios.defaults.withCredentials = true;
    // 引入vuescroll
    // import vuescroll from "vuescroll";
    // 引入vuescroll样式
    // import "vuescroll/dist/vuescroll.css";


// Vue.use(vuescroll); //使用
Vue.config.productionTip = false

// //axios拦截器
// axios.interceptors.request.use(
//     config => {
//         //添加请求头信息,为需要权限的API添加请求头信息
//         config.headers.Authorization = window.sessionStorage.getItem('token')
//         return config;
//     });

// 定义全局时间过滤器
Vue.filter('dateFormat', (e) => {
    const dt = new Date(e)
    const y = dt.getFullYear()
    const m = (`${dt.getMonth() + 1}`).padStart(2, '0')
    const d = (`${dt.getDate()}`).padStart(2, '0')
    const hh = (`${dt.getHours()}`).padStart(2, '0')
    const mm = (`${dt.getMinutes()}`).padStart(2, '0')
    const ss = (`${dt.getSeconds()}`).padStart(2, '0')

    return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

// 去除掉时间
Vue.filter('dateFormat2', (e) => {
    const dt = new Date(e)
    const y = dt.getFullYear()
    const m = (`${dt.getMonth() + 1}`).padStart(2, '0')
    const d = (`${dt.getDate()}`).padStart(2, '0')

    return `${y}-${m}-${d}`
})

// 全局过滤器(秒数转化为分钟)
Vue.filter('timeFormat', (time) => {
    // 分钟
    const minute = time / 60;
    let minutes = parseInt(minute);

    if (minutes < 10) {
        minutes = `0${minutes}`;
    }

    // 秒
    const second = time % 60;
    let seconds = Math.floor(second);
    if (seconds < 10) {
        seconds = `0${seconds}`;
    }
    return `${minutes}:${seconds}`;
})

// 为了回到页面最顶部
router.beforeEach((to, from, next) => {
    // chrome
    document.body.scrollTop = 0
        // firefox
    document.documentElement.scrollTop = 0
        // safari
    window.pageYOffset = 0
    next()
});

new Vue({
    router,
    store,
    render: (h) => h(App),
}).$mount('#app')